package com.gitee.kamismile.stone.rpc.api.invocation.support;


import com.gitee.kamismile.stone.rpc.api.invocation.IStoneFilter;
import com.gitee.kamismile.stone.rpc.common.invocation.StoneInvocationContext;
import com.gitee.kamismile.stone.rpc.common.invocation.IStoneAsyncResponse;

import java.util.List;

public class StoneInvocation extends StoneInvocationContext {
    private boolean sync = true;
    // handler链，是arrayList，可以高效地通过index访问
    private List<IStoneFilter> iStoneFilters;

    private int handlerIndex=0;

    private int timeout;

    public boolean isSync() {
        return sync;
    }

    public void setSync(boolean sync) {
        this.sync = sync;
    }

    public void next(IStoneAsyncResponse asyncResp) throws Exception {
        if(handlerIndex== iStoneFilters.size()) {
            return;
        }

        // 不必判断有效性，因为整个流程都是内部控制的
        int runIndex = handlerIndex;
        handlerIndex++;
        iStoneFilters.get(runIndex).handle(this, asyncResp);
    }

    public List<IStoneFilter> getiStoneFilters() {
        return iStoneFilters;
    }

    public void setStoneFilters(List<IStoneFilter> IHandlerList) {
        this.iStoneFilters = IHandlerList;
    }

    public int getTimeout() {
        return timeout;
    }

    public void setTimeout(int timeout) {
        this.timeout = timeout;
    }
}
